Skip to content

fix: expose the API errorCode as KeyMintApiError.error_code - #6

Merged
catsika merged 1 commit into
mainfrom
fix/api-error-code
Nov 11, 2026
Merged

catsika merged 1 commit into
mainfrom
fix/api-error-code

Conversation

@catsika

@catsika catsika commented Nov 11, 2026

Copy link
Copy Markdown
Member

Summary

  • KeyMintApiError gains error_code: the response body's errorCode catalogue string (activation_limit_reached, license_not_found, rate_limited, ...), or None when absent (no errorCode, non-JSON body, network error).
  • Backwards compatible: message, code, status and the positional constructor (message, code, status=None) are unchanged; error_code is an optional fourth argument. str(err) is still the message.
  • A JSON error body that isn't an object no longer escapes as AttributeError.
  • Floating method docstrings note that the server ignores Idempotency-Key on checkout/heartbeat/checkin.
  • README: new Error Handling section showing branching on error_code; Idempotency section corrected (replays never return floating-session secrets, because the floating endpoints ignore Idempotency-Key). example.py prints error_code.

No version bump.

Tests

pytest -q tests: 90 passed (new: with errorCode, legacy envelope plus errorCode, without errorCode, non-JSON body, non-object JSON body, constructor compatibility). ruff check . clean.

KeyMintApiError now carries the response body's errorCode catalogue string
(e.g. activation_limit_reached, license_not_found, rate_limited) as
error_code, or None when the body has none. The constructor and existing
attributes are unchanged; error_code is a new optional fourth argument.
A JSON body that isn't an object no longer escapes as AttributeError.

README: add an Error Handling section that branches on error_code, and
correct the Idempotency section: the floating endpoints ignore
Idempotency-Key, so replays never return floating-session secrets.
@catsika
catsika merged commit 7203f33 into main Nov 11, 2026
2 checks passed
@catsika
catsika deleted the fix/api-error-code branch November 11, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant